package com.yogee.topseller.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.yogee.core.http.subscribers.BaseSubscriber;
import com.yogee.topseller.R;
import com.yogee.topseller.bean.ModifyFastQueryLabelBean;
import com.yogee.topseller.bean.TagBean;

import java.util.ArrayList;
import java.util.List;

/**
* 搜索适配器
* @author hanyu
* created by 2017/7/17 14:25
*/

public class SearchListHAdapter extends RecyclerView.Adapter<SearchListHAdapter.SearchViewHolder> {

    private Context mContext;
    private List<TagBean.LabelBean> mBeans = new ArrayList<>();
    private OnItemClick listener;

    public SearchListHAdapter(Context context,OnItemClick listener){
        mContext = context;
        this.listener = listener;
    }

    public void addData(List<TagBean.LabelBean> beans){
        mBeans = beans;
        notifyDataSetChanged();
    }

    @Override
    public void onBindViewHolder(SearchViewHolder holder, final int position) {
        holder.name.setText(mBeans.get(position).getName());
        holder.layout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                listener.OnItemClickImp(mBeans.get(position).getId(),mBeans.get(position).getName());
            }
        });
    }

    @Override
    public SearchViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new SearchViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_search_list,null));
    }

    @Override
    public int getItemCount() {
        return mBeans == null ? 0 : mBeans.size();
    }



    class SearchViewHolder extends RecyclerView.ViewHolder{
        private TextView name;
        private RelativeLayout layout;
        public SearchViewHolder(View view){
            super(view);
            name = (TextView) view.findViewById(R.id.tv_tag_name);
            layout = (RelativeLayout) view.findViewById(R.id.tag_layout);
        }
    }

    public interface OnItemClick{
        void OnItemClickImp(String id,String name);
    }
}
